package org.projectwithoutname.ui.pages.input;

import model.Entity;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.PlatformUI;
import org.projectwithoutname.ui.pages.MainPage;

//import com.sun.xml.internal.stream.Entity;

public class EntityEditorInput implements IEditorInput{
	
	private Entity entity = null;
	private String mark;
	
	public void setEntity(Entity entity) {
		this.entity = entity;
	}

	public EntityEditorInput(Entity entity) {
		super();
		this.entity = entity;
	}

	@Override
	public boolean exists() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public ImageDescriptor getImageDescriptor() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getName() {
//		mark = entity.getClass().getSimpleName();
//		int x = mark.length() - 4;
//		mark = mark.substring(0, x);
		return entity.getName();
	}
	
	@Override
	public IPersistableElement getPersistable() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getToolTipText() {
		// TODO Auto-generated method stub
		return entity.getName();
	}

	@Override
	public Object getAdapter(Class adapter) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public Entity getEntity() {
		return entity;
	}
	
	public void viewRefresh(){
		MainPage view = (MainPage)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(MainPage.ID);
		view.refresh();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (super.equals(obj)) {
			return true;
		}
		if (obj instanceof EntityEditorInput) {
			return entity.equals(((EntityEditorInput) obj).getEntity());
		}
		return false;
	}
	

}
